﻿//创建时间: 2011-6-29
//创建作者: 李城
//功能说明: CMS系统 信息点击 数据操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.Config;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using TRPOP.CMS.Plugin;
using System.Data;
using TRPOP.Common;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Log
{
    public class ContentClickLogDAL
    {
        TRPOP.ComSqlDAL.ICommonDAL mICommonDAL = TRPOP.CMS.Plugin.ICommonDALAccess.GetInstance();
        /// <summary>
        /// 是否是有效的信息
        /// </summary>
        /// <param name="intID"></param>
        /// <returns></returns>
        public bool IsvalidityContent(int intID)
        {
            string strSqlString = "SELECT TOP 1 ContentId FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE ContentId=" + intID;
            using (DataSet oDataSet = mICommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().CMSDataBaseConnection))
            {
                //如果 数据集不为空 并且包含table 并且table的行数==1 
                return (oDataSet != null && oDataSet.Tables.Count > 0 && oDataSet.Tables[0].Rows.Count == 1);
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public EnumSubmitResult Save(ContentClickLogInfo info)
        {
            string strStoreProcedure = SystemInfoHelper.getSystemInfo().DBprefixTableName + "_" + "ContentClickLog_Save";
            SqlDatabase odbDataBase = mICommonDAL.GetSqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetStoredProcCommand(strStoreProcedure);
            odbDataBase.AddInParameter(odbCommand, "@dtClickTime", System.Data.DbType.DateTime, info.dtClickTime);
            odbDataBase.AddInParameter(odbCommand, "@iForegroundUserId", System.Data.DbType.Int32, info.iForegroundUserId);
            odbDataBase.AddInParameter(odbCommand, "@nvcIP", System.Data.DbType.String, info.nvcIP);
            odbDataBase.AddInParameter(odbCommand, "@nvcReferenceURL", System.Data.DbType.String, info.nvcReferenceURL);
            odbDataBase.AddInParameter(odbCommand, "@iContentID", System.Data.DbType.Int32, info.iContentID);
            odbDataBase.AddParameter(odbCommand, "@iLogId", System.Data.DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, info.iLogId);
            return mICommonDAL.ExeByCommandSqlDatabase(odbDataBase, odbCommand);
        }
        /// <summary>
        /// 根据条件获取信息
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int  GetDataRowCount(string strSQL)
        {
            using (DataSet oDataSet = mICommonDAL.GetDataSet(strSQL, SystemInfoHelper.getSystemInfo().CMSDataBaseConnection))
            {
                return (oDataSet != null && oDataSet.Tables.Count > 0) ? oDataSet.Tables[0].Rows.Count : 0;
            }
        }
        /// <summary>
        /// 根据SQL语句查询DataSet
        /// </summary>
        /// <param name="strSQLQuery"></param>
        /// <returns></returns>
        public DataSet GetDataSet(string strSQLQuery)
        {
            return mICommonDAL.GetDataSet(strSQLQuery, SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
        }
    }
}
